<?php

include "../includes/constants.php";
include "../includes/functions.php";

$query2 = "SELECT DISTINCT min_status FROM zone ORDER BY min_status ASC";
$result2 = mysql_query($query2,$db);
$db_row2 = mysql_fetch_array($result2);
do {
	echo "<a href=\"?min_status=" . $db_row2[min_status] . "\">" . $db_row2[min_status] . "</a> ";
} while ($db_row2 = mysql_fetch_array($result2));

echo "<pre>\n";

$query1 = "SELECT * FROM zone ";
// if (!isset($_GET[min_status])) {$_GET[min_status] = 0;};
if (isset($_GET[min_status]) && ($_GET[min_status] != "")) {$query1 .= " WHERE min_status='" . $_GET[min_status] . "' ";};
if (!isset($_GET[sort]) || ($_GET[sort] == "")) $_GET[sort] = "short_name";
if (!isset($_GET[dir]) || ($_GET[dir] == "")) $_GET[dir] = "ASC";
$query1 .= " ORDER BY " . $_GET[sort] . " " . $_GET[dir] . " ";
// $query1 .= " LIMIT 10 OFFSET 0 ";
$result1 = mysql_query($query1,$db);

echo "[center]
[table]
[tr][td][b]"; SortLink(short_name,'Zone'); echo "[/b][/td][td][b]"; SortLink(long_name,'Zone Title'); echo "[/b][/td][td][b]"; SortLink(min_level,'Min Level'); echo "[/b][/td][td][b]"; SortLink(flag_needed,'Flag/Key'); echo "[/b][/td][/tr]\n";

if ($db_row1 = mysql_fetch_array($result1)) {
	do {
		echo "[tr]";
		echo "[td]" . $db_row1[short_name] . "[/td]";
		echo "[td]" . $db_row1[long_name] . "[/td]";
		echo "[td]";
			if ($db_row1[min_level] > 0) echo $db_row1[min_level];
		echo "[/td]";
		echo "[td]";
			if ($db_row1[flag_needed] != "") {
				if ($db_row1[flag_needed] == 1) {echo "Flag";}
				else {echo $db_row1[flag_needed];};
			};
		echo "[/td]";
		echo "[/tr]\n";
	} while ($db_row1 = mysql_fetch_array($result1));
};

echo "[/table]
[/center]\n";

echo "</pre>\n";

?>